package com.rw.tool.util.expression.exception;

import com.rw.tool.util.expression.state.InfixExpressionState;
import com.rw.tool.util.string.StringFormatter;

public class InfixExpressionException extends ExpressionException {
    // 获得异常文本
    protected static String getErrorMessage(InfixExpressionState state, int index) {
        String errorMessage;
        switch (state) {
            case START:
                errorMessage = "An expression can only start with a number " +
                        "or an left parenthesis. Error at index {}";
                break;
            case AFTER_CALCULATION:
                errorMessage = "The sign can only be followed by " +
                        "numbers or left parentheses. Error at index {}";
                break;
            case AFTER_NUMBER:
                errorMessage = "The number can only be followed by " +
                        "addition, subtraction, multiplication and division symbol " +
                        "or right parenthesis. Error at index {}";
                break;
            case AFTER_LEFT_PARENTHESES:
                errorMessage = "The left parenthesis can only be followed by " +
                        "numbers or left parenthesis. Error at index {}";
                break;
            case AFTER_RIGHT_PARENTHESES:
                errorMessage = "The right parenthesis can only be followed by " +
                        "addition, subtraction, multiplication and division symbol " +
                        "or right parenthesis. Error at index {}";
                break;
            default:
                errorMessage = "Unknown error at index {}";
                break;
        }
        return StringFormatter.format(errorMessage, index);
    }

    public InfixExpressionException(String message) {
        super(message);
    }
}
